//
// Created by PC on 2017/12/22.
//

#ifndef READGRAPH_SPARSEGRAPH_H
#define READGRAPH_SPARSEGRAPH_H
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;

class SparseGraph{
private:
    int n,m;
    bool directed;
    vector<vector<int>> g;
public:
    SparseGraph(int n, bool directed) {
        this->n=n;
        this->m=0;
        this->directed=directed;
        g=vector<vector<int>>(n,vector<int>());
    }
    ~SparseGraph(){};

    int V(){return n;}
    int E(){return m;}

    void addEdge(int v,int w){
        assert(v>=0 && v<n);
        assert(w>=0 && w<n);

        g[v].push_back(w);
        if(v!=w && !directed)
            g[w].push_back(v);
        m++;
    }

    bool hasEdge(int v, int w) {
        assert(v>=0 && v<n);
        assert(w>=0 && w<n);
        for (int i = 0; i < g[v].size(); i++) {
            if(g[v][i]==w)
                return true;
            return false;
        }
    }
    void show(){
        for (int i = 0; i < n; ++i) {
            cout<<"vertex "<<i<<"\t";
            for (int j = 0; j < g[i].size(); j++)
                    cout<<g[i][j]<<"\t";
            cout<<endl;
        }
    }
};

#endif //READGRAPH_SPARSEGRAPH_H
